// 在一个指定的时间间隔内，函数只执行一次。

function _throttle(fn, interval) {
  let last = 0;

  return function (...args) {
    const cur = Date.now();
    if (cur - last >= interval) {
      fn.apply(this, args);
      last = cur;
    }
  };
}

const throttledLog = _throttle(() => {
  console.log(233);
}, 45);

function delay(ms) {
  return new Promise((resolve) => {
    let timer = setTimeout(() => {
      resolve();
      clearTimeout();
    }, ms);
  });
}

async function main() {
  throttledLog();
  throttledLog();
  await delay(500);
  throttledLog();
  throttledLog();
  throttledLog();
  throttledLog();
  await delay(500);
  throttledLog();
}

main();
